new Vue({
  el: '#app',
  data() {
    return {
      form: {
        serachKey: "",
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      Release: '0',
      formData: {},
      dialogFormVisible: false,
      Multistage: [{
        id: '',
        Article_SerialNumber: '',
        Unit_Price: '',
        Quantity: '',
      }],
      tableData: [{
      }],
      tablePic: [],
      Pic: [],
      loading: false,
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: [],
      Enterprise_Info_SerialNumber: $.cookie("enterprise")
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    onSerach() {				//查询方法
      console.log("搜搜")
    },
    addContract() {
      console.log("跳转")
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
    },
    handleCurrentChange(val) {
      this.form.page = val;
    },
    getList() {
      let _this = this
      $.ajax({
        type: 'POST',
        data: {
          token: $.cookie("token"),
        },
        url: DomainName + '/getArticleInfo2Action',
        success: function (data) {
          // data.forEach(item => {
          //   item.Picture_URL = DomainName + item.Picture_URL.replace('https://hospital-one.essc.top', '')
          // })
          _this.tableData = data;
          console.log(_this.tableData)
          _this.total = _this.tableData.length
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = '../../../' + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
      $.ajax({
        type: 'POST',
        data: { Data: "article_pic" },
        url: DomainName + '/GoodsFileInquiry',
        success: function (data) {
          console.log(data)
          data.forEach(item => {
            item.Picture_Url = DomainName + item.Picture_Url.replace('https://hospital-one.essc.top', '')
          })
          _this.tablePic = data;
        },
        dataType: "json"
      });
    },
    handlePreview(Article_SerialNumber) {
      this.Pic = []
      this.tablePic.filter(item => {
        return item.Picture_Type == '0' && item.Article_SerialNumber == Article_SerialNumber
      }).forEach(item => {
        this.Pic.push(item.Picture_Url)
      })
      console.log(this.Pic);
    },
    addEnterprise() {
      window.location.href = './Add.html'
    },
    // 查看详情
    showMember(Article_SerialNumber) {
      sessionStorage.setItem("Article_SerialNumber", Article_SerialNumber)
      window.location.href = './Edit.html?Article_SerialNumber=' + Article_SerialNumber
    },
    // editMember(Article_SerialNumber) {
    //   sessionStorage.setItem("Article_SerialNumber", Article_SerialNumber)
    //   window.location.href = './Edit.html?Article_SerialNumber=' + Article_SerialNumber
    // },
    // 下架
    deletMember(Article_SerialNumber) {
      const _this = this
      let detel = {};
      $.ajax({
        url: DomainName + '/ArticleInfo_Original',
        type: 'POST',
        data: { Data: Article_SerialNumber },
        success: function (res) {
          if (res.length == 1) {
            if (res[0].Row_Status == '0') {
              res[0].Row_Status = '1'
              detel = res[0];
              let data = { Data: JSON.stringify({ Modify: { article_info: [detel] } }) };
              $.ajax({
                url: DomainName + '/GoodsFileEdit',
                type: 'POST',
                data,
                success: function (res) {
                  if (res.Status === 'success') {
                    _this.$message.success("下架成功");
                    _this.getList();
                  } else {
                    _this.$message.error("操作失败，请稍后再试")
                  }
                },
                error: function () {
                  _this.$message.error("操作失败，请稍后再试")
                },
                complete: function () { _this.loading = false }
              })
            } else {
              res[0].Row_Status = '0'
              detel = res[0];
              let data = { Data: JSON.stringify({ Modify: { article_info: [detel] } }) };
              $.ajax({
                url: DomainName + '/GoodsFileEdit',
                type: 'POST',
                data,
                success: function (res) {
                  if (res.Status === 'success') {
                    _this.$message.success("上架成功");
                    _this.getList();
                  } else {
                    _this.$message.error("操作失败，请稍后再试")
                  }
                },
                error: function () {
                  _this.$message.error("删操作败，请稍后再试")
                },
                complete: function () { _this.loading = false }
              })
            }
          }


        }
      })

    },
    add_article_specifications() {
      this.Multistage.push({
        id: '',
        Article_SerialNumber: '',
        Unit_Price: '',
        Quantity: '',
      })
    },
    remove_article_specifications() {
      if (this.Multistage.length > 1) {
        this.Multistage.pop()
      } else {
        this.$message({
          message: '不能在删除了',
          type: 'warning'
        })
      }
    },
    // 公布
    stateMember(row) {
      const _this = this
      console.log(row.Article_SerialNumber)
      _this.loading = true
      $.ajax({
        type: 'POST',
        data: { Article_SerialNumber: row.Article_SerialNumber, token: $.cookie("token") },
        url: DomainName + '/getWholesaleUnitPriceAction',
        success: function (data) {
          console.log(data.length)
          if (data.length > 0) {
            $.ajax({
              url: DomainName + '/ArticleInfo_Original',
              type: 'POST',
              data: { Data: row.Article_SerialNumber, token: $.cookie("token") },
              success: function (res) {
                if (res.length == 1) {
                  if (res[0].Release_Type == '0') {
                    res[0].Release_Type = '1'
                    detel = res[0];
                    let data = { Data: JSON.stringify({ Modify: { article_info: [detel] } }) };
                    $.ajax({
                      url: DomainName + '/GoodsFileEdit',
                      type: 'POST',
                      data,
                      success: function (res) {
                        if (res.Status === 'success') {
                          _this.$message.success("发布成功");
                          _this.getList();
                        } else {
                          _this.$message.error("操作失败，请稍后再试")
                        }
                      },
                      error: function () {
                        _this.$message.error("操作失败，请稍后再试")
                      },
                      complete: function (XMLHttpRequest) {
                        _this.loading = false
                        if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                          window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                        }
                      }
                    })
                  } else {
                    res[0].Release_Type = '0'
                    detel = res[0];
                    let data = { Data: JSON.stringify({ Modify: { article_info: [detel] } }), token: $.cookie("token") };
                    $.ajax({
                      url: DomainName + '/GoodsFileEdit',
                      type: 'POST',
                      data,
                      success: function (res) {
                        if (res.Status === 'success') {
                          _this.$message.success("取消发布");
                          _this.getList();
                        } else {
                          _this.$message.error("操作失败，请稍后再试")
                        }
                      },
                      error: function () {
                        _this.$message.error("删操作败，请稍后再试")
                      },
                      complete: function (XMLHttpRequest) {
                        _this.loading = false
                        if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                          window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                        }
                      }
                    })
                  }
                }
              }
            })
          } else {
            _this.$confirm('还没有添加批发价格单, 是否添加?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              center: true
            }).then(() => {
              window.location.href = '/view/ShopManage/PriceManage/wholesalePrice/wholesalePrice.html'
            }).catch(() => {
              _this.loading = false
              _this.$message({
                type: 'info',
                message: '已取消'
              });
            });
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = '../../../' + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });

    },
    // 删除
    omitMember(Article_SerialNumber) {
      const _this = this
      let detel = {};
      $.ajax({
        url: DomainName + '/ArticleInfo_Original',
        type: 'POST',
        data: { Data: Article_SerialNumber },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '2'
            detel = res[0];
            let data = { Data: JSON.stringify({ Modify: { article_info: [detel] } }) };
            $.ajax({
              url: DomainName + '/GoodsFileEdit',
              type: 'POST',
              data,
              success: function (res) {
                if (res.Status === 'success') {
                  _this.$message.success("删除成功");
                  _this.getList();
                } else {
                  _this.$message.error("操作失败，请稍后再试")
                }
              },
              error: function () {
                _this.$message.error("操作失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              }
            })
          }
        }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 展开详细信息
    handleChildren(row) {
      _this = this
      if (!row.Children.article_specifications.length) {
        console.log(row.Children.article_specifications.length)
        $.ajax({
          url: DomainName + '/getSpecificationsAction',
          type: 'POST',
          data: {
            Article_SerialNumber: row.Article_SerialNumber,
            token: $.cookie("token")
          },

          success: function (data) {
            console.log(data)
            // data.forEach(item => {
            //   item.Picture_URL = DomainName + item.Picture_URL
            // })
            row.Children.article_specifications = data
            // console.log(expandedRows[expandedRows.length - 1].Children.article_specifications)
          },
          dataType: "json"
        });
      }

    }
  },
})

